#include <ctime>

#include "MDS.h"
#include "debug.h"


MDS *mds = NULL;

int main(int argc, char **argv)
{
	init_debug_levels(SECTION_MDS, 20);

	char ch;
	int ret = 0;
	uint64_t id;
	string conf;
	while ((ch = getopt(argc, argv, "i:c:h")) != -1) {
		switch (ch) {
		case 'i':
			id = atoi(optarg);
			break;
		case 'c':
			conf = strdup(optarg);
			break;
		case 'h':
			debug(SECTION_MDS, 10, "\n-i MDS ID\n-c configure File Name\n-h Help\n");
			return ret;
		default:
			debug(SECTION_MDS, 10, "NOT recognized option: %c", ch);
			debug(SECTION_MDS, 10, "\n-i MDS ID\n-c configure File Name\n-h Help\n");
			return ret;
		}
	}
	mds = new MDS(id, conf);
	if (0 != mds->parse_conf()) {
		debug(SECTION_MDS, 10, "parse configure file err\n");
		return ret;
	}

	//rpc, kvdb, transaction, lock service ... prepare
	mds->prepare();

	//run
	mds->run();	
	//
	mds->exit();
	return 0;
}
